const localStorage = window.localStorage
const GUIDE_OPT = 'GUIDE_OPT'
export default {
  /**
   * GUIDE_OPT 基本方法
   */
  getGuideOpt () {
    return this.getItem(GUIDE_OPT)
  },
  getGuideOptByKey (key) {
    let obj = JSON.parse(this.getGuideOpt())
    if (!obj || obj.length === 0) {
      return null
    }
    if (obj[key]) {
      return obj[key]
    } else {
      return null
    }
  },
  setGuideOpt (key, value, callback) {
    let obj = JSON.parse(this.getGuideOpt())
    if (!obj || obj.length === 0) {
      obj = {}
    }
    obj[key] = value
    let result = this.setItem(GUIDE_OPT, JSON.stringify(obj))
    if (typeof callback === 'function') {
      callback()
    }
    return result
  },
  clsGuideOpt () {
    return this.removeItem(GUIDE_OPT)
  },
  /**
   * 以下为内部基本方法
   */
  setItem (key, data) {
    return localStorage.setItem(key, data)
  },
  getItem (key) {
    return localStorage.getItem(key)
  },
  removeItem (key) {
    return localStorage.removeItem(key)
  },
  clear () {
    return localStorage.clear()
  }
}
